home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Controls GH ƒ / Control Demo ƒ / Test.c < prev    next >
C/C++ Source or Header  |  1994-02-26  |  3KB  |  123 lines

  1. void ToolBoxInit(void);
  2. pascal Boolean    myDlgFilter( DialogPtr theDlg, EventRecord *theEvent, short *itemHit );
  3. pascal void Track(ControlHandle theControl, short part);
  4. unsigned long    gLastTime;
  5.  
  6. #define WIND_WIDTH     236
  7. #define MIN_HEIGHT    130
  8. #define MAX_HEIGHT    188
  9. void main()
  10. {
  11.     DialogPtr    aDialog;
  12.     Boolean        done = FALSE;
  13.     short        itemHit;
  14.     short        value;
  15.     short        iType;
  16.     ControlHandle        iHandle;
  17.     Rect        iRect;
  18.     ToolBoxInit();
  19.     aDialog = GetNewDialog(128, 0L, (WindowPtr)-1L);
  20.     SizeWindow(aDialog, WIND_WIDTH, MIN_HEIGHT, FALSE);
  21.     SetPort(aDialog);
  22.     ShowWindow(aDialog);
  23.     GetDItem(aDialog, 2, &iType, (Handle *)&iHandle, &iRect);
  24.     while(!done)
  25.     {
  26.         ModalDialog(myDlgFilter, &itemHit);
  27.         if (itemHit == 1) done = TRUE;
  28.         else if (itemHit == 2)
  29.         {
  30.             value = GetCtlValue(iHandle);
  31.             if (value == 0) SizeWindow(aDialog,WIND_WIDTH,MAX_HEIGHT,TRUE);
  32.             else SizeWindow(aDialog, WIND_WIDTH, MIN_HEIGHT, FALSE);
  33.             SetCtlValue(iHandle, !value);
  34.         }
  35.     }
  36.     DisposDialog(aDialog);
  37.     
  38. }
  39. void ToolBoxInit(void)
  40. {
  41.     InitGraf(&thePort);
  42.     InitFonts();
  43.     FlushEvents(everyEvent, 0);
  44.     InitWindows();
  45.     InitMenus();
  46.     TEInit();
  47.     InitDialogs(0L);
  48.     InitCursor();
  49. }
  50.  
  51. pascal Boolean    myDlgFilter( DialogPtr theDlg, EventRecord
  52.             *theEvent, short *itemHit )
  53. {
  54.     short            iWinPart;
  55.     WindowPtr        whichWin;
  56.     short            iCtlPart;
  57.     ControlHandle    whichCtl, upLever, sideLever;
  58.     short            iType;
  59.     Rect            iRect;
  60.     short            value;
  61.     Point            where;
  62.     where = theEvent->where;
  63.     switch (theEvent->what)
  64.     {
  65.         case mouseDown:
  66.             iWinPart = FindWindow(where, &whichWin);
  67.             if (iWinPart == inContent && whichWin == theDlg)
  68.             {
  69.                 GlobalToLocal(&where);
  70.                 iCtlPart = FindControl(where, whichWin, &whichCtl);
  71.                 if (iCtlPart && iCtlPart != inThumb)
  72.                 {
  73.                     GetDItem(theDlg, 3, &iType, (Handle *)&upLever, &iRect);
  74.                     GetDItem(theDlg, 4, &iType, (Handle *)&sideLever, &iRect);
  75.                     if (whichCtl == upLever || whichCtl == sideLever)
  76.                     {
  77.                         gLastTime = TickCount();
  78.                         iCtlPart = TrackControl(whichCtl, where, Track);
  79.                         value = GetCtlValue(whichCtl);
  80.                         switch (iCtlPart)
  81.                         {
  82.                             case inPageUp:
  83.                                 SetCtlValue(whichCtl, value + 5);
  84.                             break;
  85.                             case inPageDown:
  86.                                 SetCtlValue(whichCtl, value - 5);
  87.                             break;
  88.                         }
  89.                         return (TRUE);
  90.                     }
  91.                 }
  92.             }
  93.         break;
  94.     }
  95.     return( FALSE );        /* or FALSE to pass it on */
  96. }
  97.  
  98. pascal void Track(ControlHandle theControl, short part)
  99. {
  100.     unsigned long    time;
  101.     short            value;
  102.     
  103.     if (part == inPageUp || part == inPageDown)
  104.     {
  105.         time = TickCount();
  106.         
  107.         if (time >= gLastTime)
  108.         {
  109.             value = GetCtlValue(theControl);
  110.             switch(part)
  111.             {
  112.                 case inPageUp:
  113.                     SetCtlValue(theControl, value + 5);
  114.                 break;
  115.                 case inPageDown:
  116.                     SetCtlValue(theControl, value - 5);
  117.                 break;
  118.             }
  119.             gLastTime = time + 5L;
  120.         }
  121.     }
  122. }
  123.